package com.flong.desgin.patterns.demeter;

import lombok.Data;
import lombok.val;
import lombok.var;

import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;

/**
 * @Author:liangjl
 * @Date: 2020/3/8-11:17
 * @Eamil:jilongliang@sina.com
 * @Description:迪米特法则（最少知道原则）
 */
public class Demeter1 {
    public static void main(String[] args) {
        SchoolManger schoolManger = new SchoolManger();
        schoolManger.printlnEmployee(new CollegeManger());
    }
}

@Data
class CollegeEmployee {
    private String id;
}

@Data
class Employee {
    private String id;
}

class SchoolManger {
    public List<Employee> getAllEmployee() {
        var list = new CopyOnWriteArrayList<Employee>();
        for (int i = 0; i < 5; i++) {
            var emp = new Employee();
            emp.setId("学院总部员工Id:" + i);
            list.add(emp);
        }
        return list;
    }

    void printlnEmployee(CollegeManger collegeManger) {
        //这行代码在它自己内部进行实现。
        collegeManger.getAllEmployee();

        System.out.println("================");
        val allEmployee1 = this.getAllEmployee();
        for (var emp : allEmployee1) {
            System.out.println(emp.getId());
        }

    }
}

class CollegeManger {

    public List<CollegeEmployee> getAllEmployee() {
        var list = new CopyOnWriteArrayList<CollegeEmployee>();
        for (int i = 0; i < 10; i++) {
            var emp = new CollegeEmployee();
            emp.setId("学院员工Id:" + i);
            list.add(emp);
        }
        return list;
    }
    void printlnEmployee() {
        val allEmployee = this.getAllEmployee();
        for (var emp : allEmployee) {
            System.out.println(emp.getId());
        }
    }

}
